{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "* By: Illya Barziy\n",
    "* Email: illyabarziy@gmail.com\n",
    "* Reference: Advances in Financial Machine Learning, Chapter-14"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Chapter 14 Backtest Statistics"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Introduction"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Whenever a strategy is created, it's performance has to be tested and reported. This chapter covers some of the statistics that are used for understanding the characteristics of a strategy related to levels of risk and return. It also provides tools to test if the strategy satisfies desired profitability benchmarks (Sharpe ratio in particular). Statistics in this chapter cover the following topics:\n",
    "- Drawdown\n",
    "- Time under water\n",
    "- Herfindahl-Hirschman Index or Concentration of returns\n",
    "- Sharpe ratio\n",
    "- Probabilistic Sharpe ratio\n",
    "- Deflated Sharpe ratio\n",
    "\n",
    "In this notebook, the exercises from Chapter-14 in the book \"Advances in Financial Machine Learning\" are implemented."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [],
   "source": [
    "import pandas as pd\n",
    "import numpy as np\n",
    "import scipy.stats as ss\n",
    "import matplotlib.pyplot as plt\n",
    "import mlfinlab as ml"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Question-14.1"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### A strategy exhibits a high turnover, high leverage, and high number of bets, with a short holding period, low return on execution costs, and a high Sharpe ratio. Is it likely to have large capacity? What kind of strategy do you think it is?"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Looking closer to the characteristics:\n",
    "- A high turnover means that the average amount traded per year is higher than the average annual amount of Assets Under Management (AUM). This situation indicates that the positions are often changed - tuned or flipped.  \n",
    "- High leverage means that the amounts borrowed for strategy execution are high compared to the AUM.\n",
    "- The high number of bets occurs when positions are changed frequently. It shows that the strategy certainly doesn't have long holding periods.\n",
    "- Short holding periods go in line with the previous characteristic.\n",
    "- low return on execution cases - when the ratio between dollar performance (including brokerage fees and slippage costs) and total execution costs is low, there are high chances that strategy won't survive worse-than-expected execution.\n",
    "- The high Sharpe ratio shows that returns are high and have a relatively low level of volatility.\n",
    "\n",
    "Capacity is defined as the highest AUM that delivers a target risk-adjusted performance. Since the strategy shows high leverage, it isn't likely to have high capacity since a big portion of resources is borrowed.\n",
    "\n",
    "The strategy described above may be either a statistical arbitrage or an intraday trading strategy."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Question-14.2"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### On the dollar bars dataset for E-mini S&P 500 futures, compute\n",
    "### (a) HHI index on positive returns"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "#### !!!Note that this notebook uses a full dataset. If one tries to run the notebook on sample data provided in the GitHub repository the results will be different!!!\n",
    "\n",
    "#### We use log returns in the examples below"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "We assume no transaction costs and the amount invested is the first observed price of a contract"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [],
   "source": [
    "#Read in data\n",
    "data = pd.read_csv('../Sample-Data/dollar_bars.csv')\n",
    "data.index = pd.to_datetime(data['date_time'])\n",
    "data = data.drop('date_time', axis=1)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>open</th>\n",
       "      <th>high</th>\n",
       "      <th>low</th>\n",
       "      <th>close</th>\n",
       "      <th>cum_vol</th>\n",
       "      <th>cum_dollar</th>\n",
       "      <th>cum_ticks</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>date_time</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>2011-07-31 23:31:58.810</th>\n",
       "      <td>1306.00</td>\n",
       "      <td>1308.75</td>\n",
       "      <td>1301.75</td>\n",
       "      <td>1305.75</td>\n",
       "      <td>53658</td>\n",
       "      <td>70035704.75</td>\n",
       "      <td>14115</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2011-08-01 02:55:17.443</th>\n",
       "      <td>1305.75</td>\n",
       "      <td>1309.50</td>\n",
       "      <td>1304.00</td>\n",
       "      <td>1306.50</td>\n",
       "      <td>53552</td>\n",
       "      <td>70006277.00</td>\n",
       "      <td>15422</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2011-08-01 07:25:56.319</th>\n",
       "      <td>1306.75</td>\n",
       "      <td>1309.75</td>\n",
       "      <td>1304.75</td>\n",
       "      <td>1305.00</td>\n",
       "      <td>53543</td>\n",
       "      <td>70000901.00</td>\n",
       "      <td>14727</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2011-08-01 08:33:10.903</th>\n",
       "      <td>1305.00</td>\n",
       "      <td>1305.00</td>\n",
       "      <td>1299.00</td>\n",
       "      <td>1300.00</td>\n",
       "      <td>53830</td>\n",
       "      <td>70094217.75</td>\n",
       "      <td>14987</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2011-08-01 10:51:41.842</th>\n",
       "      <td>1300.00</td>\n",
       "      <td>1307.75</td>\n",
       "      <td>1299.00</td>\n",
       "      <td>1307.75</td>\n",
       "      <td>53734</td>\n",
       "      <td>70033006.25</td>\n",
       "      <td>14499</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-02-01 20:55:01.064</th>\n",
       "      <td>2704.00</td>\n",
       "      <td>2704.00</td>\n",
       "      <td>2700.75</td>\n",
       "      <td>2702.50</td>\n",
       "      <td>25921</td>\n",
       "      <td>70045841.00</td>\n",
       "      <td>4040</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-02-01 20:59:21.030</th>\n",
       "      <td>2702.50</td>\n",
       "      <td>2705.00</td>\n",
       "      <td>2702.50</td>\n",
       "      <td>2704.75</td>\n",
       "      <td>25890</td>\n",
       "      <td>70006624.75</td>\n",
       "      <td>4172</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-02-01 20:59:59.015</th>\n",
       "      <td>2704.75</td>\n",
       "      <td>2706.00</td>\n",
       "      <td>2704.50</td>\n",
       "      <td>2704.50</td>\n",
       "      <td>25895</td>\n",
       "      <td>70050302.25</td>\n",
       "      <td>2596</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-02-01 21:00:53.234</th>\n",
       "      <td>2704.50</td>\n",
       "      <td>2705.00</td>\n",
       "      <td>2703.50</td>\n",
       "      <td>2704.00</td>\n",
       "      <td>25987</td>\n",
       "      <td>70277088.25</td>\n",
       "      <td>2072</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-02-01 21:11:59.213</th>\n",
       "      <td>2704.00</td>\n",
       "      <td>2705.25</td>\n",
       "      <td>2703.75</td>\n",
       "      <td>2704.25</td>\n",
       "      <td>26055</td>\n",
       "      <td>70467907.75</td>\n",
       "      <td>3692</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>85331 rows × 7 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "                            open     high      low    close  cum_vol  \\\n",
       "date_time                                                              \n",
       "2011-07-31 23:31:58.810  1306.00  1308.75  1301.75  1305.75    53658   \n",
       "2011-08-01 02:55:17.443  1305.75  1309.50  1304.00  1306.50    53552   \n",
       "2011-08-01 07:25:56.319  1306.75  1309.75  1304.75  1305.00    53543   \n",
       "2011-08-01 08:33:10.903  1305.00  1305.00  1299.00  1300.00    53830   \n",
       "2011-08-01 10:51:41.842  1300.00  1307.75  1299.00  1307.75    53734   \n",
       "...                          ...      ...      ...      ...      ...   \n",
       "2019-02-01 20:55:01.064  2704.00  2704.00  2700.75  2702.50    25921   \n",
       "2019-02-01 20:59:21.030  2702.50  2705.00  2702.50  2704.75    25890   \n",
       "2019-02-01 20:59:59.015  2704.75  2706.00  2704.50  2704.50    25895   \n",
       "2019-02-01 21:00:53.234  2704.50  2705.00  2703.50  2704.00    25987   \n",
       "2019-02-01 21:11:59.213  2704.00  2705.25  2703.75  2704.25    26055   \n",
       "\n",
       "                          cum_dollar  cum_ticks  \n",
       "date_time                                        \n",
       "2011-07-31 23:31:58.810  70035704.75      14115  \n",
       "2011-08-01 02:55:17.443  70006277.00      15422  \n",
       "2011-08-01 07:25:56.319  70000901.00      14727  \n",
       "2011-08-01 08:33:10.903  70094217.75      14987  \n",
       "2011-08-01 10:51:41.842  70033006.25      14499  \n",
       "...                              ...        ...  \n",
       "2019-02-01 20:55:01.064  70045841.00       4040  \n",
       "2019-02-01 20:59:21.030  70006624.75       4172  \n",
       "2019-02-01 20:59:59.015  70050302.25       2596  \n",
       "2019-02-01 21:00:53.234  70277088.25       2072  \n",
       "2019-02-01 21:11:59.213  70467907.75       3692  \n",
       "\n",
       "[85331 rows x 7 columns]"
      ]
     },
     "execution_count": 4,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "data"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [],
   "source": [
    "#Transforming data to log returns from one long position\n",
    "logret_series = np.log(data['close']).diff()[1:]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAYkAAAD4CAYAAAAZ1BptAAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADh0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uMy4xLjEsIGh0dHA6Ly9tYXRwbG90bGliLm9yZy8QZhcZAAATJUlEQVR4nO3df6zd9X3f8edrplBK12HCuGMYzVTyH3VilaQWIGV/3CabMUSdqZZIIFRMwuSuA62R/EedZhJRCBJUot1QUzZ3sWKkLoSljbAKHfMoV22mQiAJjeNQZpd4wcECZaZpLtESuXvvj/O55ADn43t9f517r58P6eh8z/t8vt/zOW+f65e/P+5xqgpJkkb5e+OegCRp5TIkJEldhoQkqcuQkCR1GRKSpK5zxj2B+br44otr48aN457GGXv99de54IILxj2NFcne9Nmb0exLX683X/nKV75bVf9wrttZtSGxceNGnn322XFP44xNTU0xOTk57mmsSPamz96MZl/6er1J8r/PZDsebpIkdRkSkqQuQ0KS1GVISJK6DAlJUpchIUnqMiQkSV2GhCSpy5CQJHWt2t+4lta6jXsefWN595ZT3NoeH7vnA+Oaks5C7klIkroMCUlSlyEhSeoyJCRJXYaEJKnLkJAkdRkSkqQuQ0KS1GVISJK6DAlJUpchIUnqMiQkSV2GhCSpy5CQJHUZEpKkLkNCktRlSEiSugwJSVKXISFJ6jIkJElds4ZEksuTPJnk+SSHk/x6q38iyXeSPNdu1w+t87EkR5O8kOTaofr2VjuaZM9Q/YokTyc5kuTzSc5d7DcqSTpzc9mTOAXsrqqfA64Bbk+yuT33O1V1Zbs9BtCeuxF4J7Ad+L0k65KsAz4NXAdsBm4a2s69bVubgNeA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J0l9Uy9GatmMvX0cyMOd7+4fAPgJNzXHc1W0hv1roF9SbJBuCLwC1V9dezvZiHm5bGAWDmipydwCMjxjwObEuyvl3hs63VSPIpBn+oH12GuS63BfVmjZnL19EM9+uDwJ/W4KzjAeDGdhXLFcAm4MvLNO/lsJDerHXz7k07hP0o8LGq+p9zerVxn6lfizcGx/6eAI60+4tafSuD/3VvZtxHGJxwPAp8uNU2MNgtfB54rt3+1bjf00roTav/FoN/Jf2/dv+Jcb+nBfbjeuB/Mbha5eOt9kngX7TlnwT+a+vDl4GfHVr34229F1hDV8AtUm+OMfiX83T7nGxe7vmvxN4A/w54fejvlueAS073Wn4thySpy8NNkqQuQ0KS1GVISJK6DAlJUpchIUnqMiQkSV2GhCSp6/8Deg6Ak0TdHgYAAAAASUVORK5CYII=\n",
      "text/plain": [
       "<Figure size 432x288 with 1 Axes>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "logret_series.hist(bins=50)\n",
    "plt.show()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [],
   "source": [
    "#Using mlfinlab package function for detailed concentration output\n",
    "pos_concentr, neg_concentr, hourly_concentr = ml.backtest_statistics.all_bets_concentration(logret_series, frequency='H')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "HHI index on positive log returns is 2.5930058463712052e-05\n"
     ]
    }
   ],
   "source": [
    "print('HHI index on positive log returns is' , pos_concentr)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Concentration (or HHI index) on positive log returns is fairly close to zero. From its properties, we can conclude that the log returns distribution is likely to have no fat right tail."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### (b) HHI index on negative returns"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "HHI index on negative log returns is 2.4569679802262173e-05\n"
     ]
    }
   ],
   "source": [
    "print('HHI index on negative log returns is' , neg_concentr)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Concentration (or HHI index) on negative log returns is fairly close to zero, the same as for positive ones. From its properties, we can conclude that the log returns distribution is likely to have no fat left tail."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### (c) HHI index on time between bars"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "HHI index on log returns divided into hourly bins is 5.438411110913481e-05\n"
     ]
    }
   ],
   "source": [
    "print('HHI index on log returns divided into hourly bins is' , hourly_concentr)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Concentration (or HHI index) on time between bars (from the observed dataset, roughly 1h between bars) is low. This means bets are not concentrated in time or are close to being uniformly distributed across time."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### (d) The 95-percentile DD"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {},
   "outputs": [],
   "source": [
    "#Getting series of prices to represent the value of one long portfolio\n",
    "price_series = data['close'][1:]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAX0AAAD9CAYAAABQvqc9AAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADh0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uMy4xLjEsIGh0dHA6Ly9tYXRwbG90bGliLm9yZy8QZhcZAAAgAElEQVR4nO3dd3hUZfbA8e9JgNB7kE4AkY6USFEQRFQUV+yKdVdd7Lvuuu4PsS421r6sbS2svfcVFMECoqAmigKCdCGI9BJCSTu/P+6dyU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q6q2qOicqURkTZZb0TY0lIjeJyM8iMgfo7rb9UUS+FZEfROQtEakvIkcCpwD3icgiEenqfn0kIpki8oWI9AjzGl7HPisiZ7rb14nI3SKyQEQyRGSgiMwSkdUickXAeW5w4/pRRP5R6T8ck7As6ZsaSUQGAefiTOJ+OnCEu+ltVT1CVQ8HluE8Dv8VThGsG1S1v6quxpm+7lpVHQT8DacOeogwxxa3QVWHAV8AzwJn4jySP8WN9Xic+XAHA/2BQSJydEV/BsZ4iZkqm8ZE2QjgHVXdByAivsqGfUTkTqApzpR0s4ofKM6cy0cCbwRUuU2pQCy+114MNFTVbCBbRA6ISFPgePfre3e/hjhvAvMq8JrGeLKkb2oyrxojzwKnquoPIvJ7YJTHPknALlXtH6U4fHVWCgOWfeu1cOZIvUdV/xOl1zMmLOveMTXVPOA0EaknIo1wJqMGaARsEpHaOLMY+WS721DVPcBaETkLnEktROTwEl7Lf2w5zQIucT9hICLtRKRVBc5nTFiW9E2NpKrfAa/hTEn3Fk5/Ojg1zL8GZgPLAw55FbhBRL4Xka44bwiXisgPwFKcOUvDKX5sWWP9GHgZWCAii4E3qdibiDFhWZVNY4xJIHalb4wxCcRu5BoTIRG5CTirWPMbqnpXdcRjTHlY944xxiQQ694xxpgEYknfGGMSiCV9Y4xJIJb0jTEmgVjSN8aYBPL/sPPCEjLu4c4AAAAASUVORK5CYII=\n",
      "text/plain": [
       "<Figure size 432x288 with 1 Axes>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "#Looking at the performance of a protfolio\n",
    "price_series.plot()\n",
    "plt.show()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "metadata": {},
   "outputs": [],
   "source": [
    "#Using mlfinlab package function to get drawdowns and time under water series\n",
    "drawdown, tuw = ml.backtest_statistics.drawdown_and_time_under_water(price_series, dollars = False)\n",
    "drawdown_dollars, _ = ml.backtest_statistics.drawdown_and_time_under_water(price_series, dollars = True)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "The 95th percentile of Drawdown is 0.01769512497257557\n"
     ]
    }
   ],
   "source": [
    "print('The 95th percentile of Drawdown is' , drawdown.quantile(.95))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "The 95th percentile of Drawdown in dollars is 34.912499999999966\n"
     ]
    }
   ],
   "source": [
    "print('The 95th percentile of Drawdown in dollars is' , drawdown_dollars.quantile(.95))"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "This means that from the observed set, 95% of drawdowns are below 0.018 or 1.8% of the portfolio (If assuming long position). In the dollar equivalent, it is $34.91."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### (e) The 95-percentile TuW"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "The 95th percentile of Time under water 0.031676884150598425\n"
     ]
    }
   ],
   "source": [
    "print('The 95th percentile of Time under water' , tuw.quantile(.95))"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "From the results, 95% of the time under water is below 0.0317 years, or 7.98 trading days."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### (f) Annualized average return"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "We use the formula:\n",
    "\n",
    "$AnnualizedAverageReturn = \\frac{EndingValue}{BeginningValue}^{\\frac{1}{Years}}-1 $"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "metadata": {},
   "outputs": [],
   "source": [
    "#Using simple formula for annual return calculation\n",
    "days_observed = (price_series.index[-1] - price_series.index[0]) / np.timedelta64(1, 'D')\n",
    "cumulated_return = price_series[-1]/price_series[0]\n",
    "\n",
    "#Using 365 days instead of 252 as days observed are calculated as calendar\n",
    "#days between the first observation and the last\n",
    "annual_return = (cumulated_return)**(365/days_observed) - 1"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Annualized average return from the portfolio is 0.10169027020627053\n"
     ]
    }
   ],
   "source": [
    "print('Annualized average return from the portfolio is' , annual_return)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "So, the average annual return from the given data is 10.169%"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### (g) Average returns from hits (positive returns)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Average log return from positive bars is 0.00099482493140664 and counter is 41280\n",
      "Average log return from positive bars grouped by days is 0.005951808843591273 and counter is 1117\n"
     ]
    }
   ],
   "source": [
    "print('Average log return from positive bars is' , logret_series[logret_series>0].mean(), \n",
    "      'and counter is', logret_series[logret_series>0].count())\n",
    "\n",
    "#Also looking at returns grouped by days\n",
    "logret_by_days = logret_series.groupby(pd.Grouper(freq='D')).sum()\n",
    "logret_by_days = logret_by_days[logret_by_days!=0]\n",
    "print('Average log return from positive bars grouped by days is' , \n",
    "      logret_by_days[logret_by_days>0].mean(), 'and counter is', \n",
    "      logret_by_days[logret_by_days>0].count())"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Average log return from bar hits is 0.00099 and from day hits 0.00595. Hits from bars are 37 times more frequent than daily hits."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### (h) Average return from misses (negative returns)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 20,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Average log return from negative bars is -0.0010137295473279077 and counter is 39792\n",
      "Average log return from negative bars grouped by days is -0.006225156106306478 and counter is 951\n"
     ]
    }
   ],
   "source": [
    "print('Average log return from negative bars is' , logret_series[logret_series<0].mean(),\n",
    "     'and counter is', logret_series[logret_series<0].count())\n",
    "\n",
    "print('Average log return from negative bars grouped by days is' , \n",
    "      logret_by_days[logret_by_days<0].mean(), 'and counter is',\n",
    "      logret_by_days[logret_by_days<0].count())"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Average log return from bar misses is -0.101% and from day hits -0.623%. The number of misses is just slightly (3.6%) lower than the number of hits."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### (i) Annualized SR"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "$AnnualizedSR = \\frac{Mean(Returns)}{StandardDeviation(Returns)}*\\sqrt{ReturnsObservedPerYear}$"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 21,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Annualized Sharpe Ratio is 0.6207628576848087\n"
     ]
    }
   ],
   "source": [
    "#Uning mlfinlab package function to get SR\n",
    "annualized_sr = ml.backtest_statistics.sharpe_ratio(logret_by_days, entries_per_year=252, risk_free_rate=0)\n",
    "print('Annualized Sharpe Ratio is' , annualized_sr)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "The annualized Sharpe ratio for the long position on the portfolio is fairly low at 0.62."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### (j) Information ratio, where the benchmark is the risk-free rate"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Information ratio is the annualized ratio between the average excess return and the tracking error. The excess return is measured as the portfolio’s return in excess of the benchmark’s return. The tracking error is estimated as the standard deviation of the excess returns.\n",
    "\n",
    "$InformationRatio = \\frac{Mean(Returns - Benchmark)}{StandardDeviation(Returns - Benchmark)}*\\sqrt{ReturnsObservedPerYear}$\n",
    "\n",
    "For the benchmark, let's assume the risk-free rate to be the 10-year treasury rate at the beginning of 2020 at 1.8% per year"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 22,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Information ratio (with yearly risk-free rate assumed to be 1.8%) is 0.4959356818028273\n"
     ]
    }
   ],
   "source": [
    "#Stating the risk-free ratio and trading days per year\n",
    "risk_free_ratio = 0.018\n",
    "trading_days = 252\n",
    "\n",
    "#Calculating excess returns above the risk-free ratio\n",
    "#This means subtracting the benchmark from daily returns\n",
    "\n",
    "#Daily returns adjusted for taking compounding effect into account\n",
    "daily_risk_free_ratio = (1 + risk_free_ratio)**(1/trading_days) - 1\n",
    "log_daily_risk_free_ratio = np.log(1 + daily_risk_free_ratio)\n",
    "\n",
    "#Using mlfinlab package function to get Information ratio\n",
    "information_ratio = ml.backtest_statistics.information_ratio(logret_by_days, \n",
    "                       log_daily_risk_free_ratio, entries_per_year=trading_days)\n",
    "\n",
    "print('Information ratio (with yearly risk-free rate assumed to be 1.8%) is' , information_ratio)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Information ratio is the Sharpe ratio equivalent of a portfolio that measures its performance relative to a benchmark. It is lower than the Sharpe ratio, as expected, as we're measuring the relative performance of a portfolio. It is still positive, which means that the portfolio outperforms the benchmark of a risk-free rate."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### (k) PSR"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "The Probabilistic Sharpe ratio (PSR) provides an adjusted estimate of SR, by removing the inflationary effect caused by short series with skewed and/or fat-tailed returns.\n",
    "\n",
    "As no benchmark Sharpe ratio is provided, let's assume it to be at 0.6, a bit lower than the previously calculated Annual SR."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 23,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Probabilistic Sharpe Ratio with benchmark SR of 0.6 is 0.7990555934340262\n"
     ]
    }
   ],
   "source": [
    "#Using mlfinlab package function to get PSR\n",
    "probabilistic_sr = ml.backtest_statistics.probabilistic_sharpe_ratio(observed_sr=annualized_sr, \n",
    "                                                                     benchmark_sr=0.6, \n",
    "                                                                     number_of_returns=days_observed, \n",
    "                                                                     skewness_of_returns=logret_by_days.skew(), \n",
    "                                                                     kurtosis_of_returns=logret_by_days.kurt())\n",
    "print('Probabilistic Sharpe Ratio with benchmark SR of 0.6 is' , probabilistic_sr)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "As the PSR value is lower than 0.95, we have to reject the hypothesis that the Sharpe ratio is 0.6 for the 5% significance level."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 24,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Probabilistic Sharpe Ratio with benchmark SR of 0.58 is 0.9500879214252643\n"
     ]
    }
   ],
   "source": [
    "probabilistic_sr_adj = ml.backtest_statistics.probabilistic_sharpe_ratio(observed_sr=annualized_sr, \n",
    "                                                                         benchmark_sr=0.58, \n",
    "                                                                         number_of_returns=days_observed, \n",
    "                                                                         skewness_of_returns=logret_by_days.skew(), \n",
    "                                                                         kurtosis_of_returns=logret_by_days.kurt())\n",
    "print('Probabilistic Sharpe Ratio with benchmark SR of 0.58 is' , probabilistic_sr_adj)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "However, with the benchmark SR of 0.58, the PSR is just above 0.95. So, we can assume Sharpe ratio to be 0.58 for the 5% significance level."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### (l) DSR, where we assume there were 100 trials, and the variance of the trials’ SR was 0.5"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Deflated Sharpe Ratio (DSR) is a PSR where the rejection threshold is adjusted to reflect the multiplicity of trials. DSR is estimated as PSR[SR∗], where the benchmark Sharpe ratio, SR∗, is no longer user-defined but calculated from SR estimate trails."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 25,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Deflated Sharpe Ratio with 100 trails and 0.5 variance is 0.0\n"
     ]
    }
   ],
   "source": [
    "#Using mlfinlab package function to get DSR. Passing standard deviation of trails and\n",
    "#number of trails as a parameter, also flag estimates_param.\n",
    "deflated_sr = ml.backtest_statistics.deflated_sharpe_ratio(observed_sr=annualized_sr, \n",
    "                                                           sr_estimates=[0.5**(1/2), 100], \n",
    "                                                           number_of_returns=days_observed, \n",
    "                                                           skewness_of_returns=logret_by_days.skew(), \n",
    "                                                           kurtosis_of_returns=logret_by_days.kurt(),\n",
    "                                                           estimates_param=True)\n",
    "print('Deflated Sharpe Ratio with 100 trails and 0.5 variance is' , deflated_sr)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "The Deflated Sharpe ratio is extremely low. This is because the benchmark in the estimate is set high:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 26,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Benchmark Sharpe ratio used in DSR is 1.7894064662732079\n"
     ]
    }
   ],
   "source": [
    "#DSR function also allows the output of benchmark SR calculated when benchmark_out \n",
    "#flag is set to True.\n",
    "benchmark_sr_dsr = ml.backtest_statistics.deflated_sharpe_ratio(observed_sr=annualized_sr, \n",
    "                                                                sr_estimates=[0.5**(1/2), 100], \n",
    "                                                                number_of_returns=days_observed, \n",
    "                                                                skewness_of_returns=logret_by_days.skew(), \n",
    "                                                                kurtosis_of_returns=logret_by_days.kurt(),\n",
    "                                                                estimates_param=True, benchmark_out=True)\n",
    "\n",
    "print('Benchmark Sharpe ratio used in DSR is' , benchmark_sr_dsr)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "If the number of trails was smaller, the results would be different:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 27,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Benchmark Sharpe ratio if number of trails is decreased to 3 is 0.6030238422545333\n",
      "Deflated Sharpe Ratio with 3 trails and 0.5 variance is 0.7630574203326299\n"
     ]
    }
   ],
   "source": [
    "benchmark_sr_dsr_adj = ml.backtest_statistics.deflated_sharpe_ratio(observed_sr=annualized_sr, \n",
    "                                                                    sr_estimates=[0.5**(1/2), 3], \n",
    "                                                                    number_of_returns=days_observed, \n",
    "                                                                    skewness_of_returns=logret_by_days.skew(), \n",
    "                                                                    kurtosis_of_returns=logret_by_days.kurt(),\n",
    "                                                                    estimates_param=True, benchmark_out=True)\n",
    "\n",
    "print('Benchmark Sharpe ratio if number of trails is decreased to 3 is' , benchmark_sr_dsr_adj)\n",
    "\n",
    "deflated_sr = ml.backtest_statistics.deflated_sharpe_ratio(observed_sr=annualized_sr, \n",
    "                                                           sr_estimates=[0.5**(1/2), 3], \n",
    "                                                           number_of_returns=days_observed, \n",
    "                                                           skewness_of_returns=logret_by_days.skew(), \n",
    "                                                           kurtosis_of_returns=logret_by_days.kurt(),\n",
    "                                                           estimates_param=True)\n",
    "print('Deflated Sharpe Ratio with 3 trails and 0.5 variance is' , deflated_sr)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Question-14.3"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Consider a strategy that is long one futures contract on even years, and is short one futures contract on odd years.\n",
    "\n",
    "### (a) Repeat the calculations from exercise 2"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "We assume no transaction costs and the amount invested is the first observed price of a contract"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 28,
   "metadata": {},
   "outputs": [],
   "source": [
    "#To change the existing series of returns from one long position to the one \n",
    "#described above, we multiply odd years log returns by -1.\n",
    "logret_series_with_short = logret_series *(1 - 2 * (logret_series.index.year % 2))\n",
    "\n",
    "#Portfolio prices are calculated by reversing the log returns to cumulated sum\n",
    "#of normal returns series and multiplying them by the price of a contract\n",
    "price_series_with_short = price_series[0] * np.exp(logret_series_with_short.cumsum()) "
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### _Distribution of returns_"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 29,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAYMAAAD4CAYAAAAO9oqkAAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADh0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uMy4xLjEsIGh0dHA6Ly9tYXRwbG90bGliLm9yZy8QZhcZAAAUi0lEQVR4nO3db4xd9X3n8fenJhBKt8VAmfXaaE1VP4gTqyQdEaTsgym0YIi6pmoiGaFiElbudkHbSH4Q06xENoQVVKJZsU3YdRcrZtWNYdNGWMFd1ksZdbNq+JNAcQxlPSHeMMECZU1ohqhEk/3ug/uzc9fc8VzPn3vHM++XdHXP/Z7fOfP7zvXMx+fcc++kqpAkrWw/M+wJSJKGzzCQJBkGkiTDQJKEYSBJAs4a9gTm6qKLLqr169cPexonvPXWW5x33nnDnsbQ2P/K7X8l9w5nXv/f+MY3vl9Vv3hy/YwNg/Xr1/PMM88MexonjI+PMzY2NuxpDI39r9z+V3LvcOb1n+R/96p7mkiSZBhIkgwDSRKGgSQJw0CShGEgScIwkCRhGEiSMAwkSZzB70CWhm39zkdPLO/YNM3N7fGRuz88rClJc+aRgSTJMJAkGQaSJAwDSRJ9hEGSdyd5KsnfJDmU5F+3+qVJnkxyOMlDSc5u9XPa44m2fn3Xvm5v9ZeSXNNV39xqE0l2LnybkqRT6efI4G3gyqr6FeAyYHOSK4B7gM9V1QbgDeCWNv4W4I2q+mXgc20cSTYCW4H3ApuBLyRZlWQV8HngWmAjcEMbK0kakFnDoDqm2sN3tVsBVwJfbvU9wPVteUt7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       "<Figure size 432x288 with 1 Axes>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "logret_series_with_short.hist(bins=50)\n",
    "plt.show()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "On the histogram of log returns looks about the same as the previous one"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### _Positive, negative and time concentrations (or HHI)_"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 30,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "HHI index of positive log returns is 2.670439671024535e-05\n",
      "HHI index of negative log returns is 2.388044051983817e-05\n",
      "HHI index of log returns divided by hourly bins is 5.438411110913481e-05\n"
     ]
    }
   ],
   "source": [
    "pos_concentr, neg_concentr, hourly_concentr = ml.backtest_statistics.all_bets_concentration(logret_series_with_short, frequency='H')\n",
    "print('HHI index of positive log returns is' , pos_concentr)\n",
    "print('HHI index of negative log returns is' , neg_concentr)\n",
    "print('HHI index of log returns divided by hourly bins is' , hourly_concentr)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "The concentration of positive log returns has slightly increased, while the concentration of negative has decreased. This would mean that the distribution is now less likely to have a left fat tail and more likely to have a fat right tail.\n",
    "\n",
    "Concentration in time is exactly the same, as the returns occur with the same frequency as in the previous portfolio."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### _Drawdown and Time under water 95th percentile_"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 31,
   "metadata": {},
   "outputs": [],
   "source": [
    "#Using mlfinlab package function to get drawdowns and time under water series\n",
    "drawdown, tuw = ml.backtest_statistics.drawdown_and_time_under_water(price_series_with_short, dollars = False)\n",
    "drawdown_dollars, _ = ml.backtest_statistics.drawdown_and_time_under_water(price_series_with_short, dollars = True)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 32,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "The 95th percentile of Drawdown is 0.10633765341973031\n"
     ]
    }
   ],
   "source": [
    "print('The 95th percentile of Drawdown is' , drawdown.quantile(.95))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 33,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "The 95th percentile of Drawdown in dollars is 167.4492843785195\n"
     ]
    }
   ],
   "source": [
    "print('The 95th percentile of Drawdown in dollars is' , drawdown_dollars.quantile(.95))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 34,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAX0AAAD9CAYAAABQvqc9AAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADh0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uMy4xLjEsIGh0dHA6Ly9tYXRwbG90bGliLm9yZy8QZhcZAAAgAElEQVR4nO2dd5gUVdbG3zMzzMCQhSEjQ85BGAElCwLKKiZ2zfFbdBXXsOsKKMqiKKu7urrmgKirIGYWkGhAkDTkDAMMMOTMECaf74+q7qnuruqu6q7uru4+v+eZh+pbt6oP3dWnbp177nuImSEIgiAkBknRNkAQBEGIHOL0BUEQEghx+oIgCAmEOH1BEIQEQpy+IAhCAiFOXxAEIYFIibYB/qhduzZnZmZG2wxBEISYYtWqVceYOUNvn6OdfmZmJrKzs6NthiAIQkxBRHuM9kl4RxAEIYEQpy8IgpBABHT6RDSZiI4Q0Uav9oeJaBsRbSKilzTtY4goR903RNM+VG3LIaLR9v43BEEQBDOYielPAfAGgE9cDUQ0AMBwAJ2YuZCI6qjt7QDcDKA9gAYAFhBRK/WwNwFcCSAPwEoimsHMm+36jwiCIAiBCej0mXkREWV6Nf8JwCRmLlT7HFHbhwOYprbvJqIcAN3VfTnMvAsAiGia2lecviAIQgQJNqbfCkAfIlpORL8Q0aVq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5cQAAAABJRU5ErkJggg==\n",
      "text/plain": [
       "<Figure size 432x288 with 1 Axes>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "price_series_with_short.plot()\n",
    "plt.show()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "The results show that the 95th Drawdown percentile is 0.106. However, the portfolio from the starting value of 1305.75 decreased up to 1070.93 (almost -18%). Why is that?\n",
    "\n",
    "It's because we had many small drawdowns in the period of 2011.08-2012.09. In 2012.09 a peak of portfolio value is observed. Since that time, there was one big drawdown up till the last day. Therefore, quantile measure here is not informative, as we have a set of small drawdowns and a 1 huge outlier at the end of the time period."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 35,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Maximum Drawdown is 0.3315840502520586\n"
     ]
    }
   ],
   "source": [
    "print('Maximum Drawdown is', max(drawdown))"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "The same situation is observed with the Time under water. Mlfinlab function also includes time between the last high watermark and last observation in returns as the last Time under water element (even though it's not time between two high watermarks). Without this element the estimations of Time under water can be biased. It's clearly seen in our example, where the last Time under water over 6 years."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 36,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "The 95th percentile of Time under water 0.12496082496813973\n"
     ]
    }
   ],
   "source": [
    "print('The 95th percentile of Time under water' , tuw.quantile(.95))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 37,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Maximum Time under water is 6.382838106544638\n"
     ]
    }
   ],
   "source": [
    "print('Maximum Time under water is', max(tuw))"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### _Annualized average return_"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 38,
   "metadata": {},
   "outputs": [],
   "source": [
    "cumulated_return_with_short = price_series_with_short[-1]/price_series_with_short[0]\n",
    "annual_return = (cumulated_return_with_short)**(365/days_observed) - 1"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 39,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Annualized average return from the portfolio is -0.026046796015894658\n"
     ]
    }
   ],
   "source": [
    "print('Annualized average return from the portfolio is' , annual_return)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "The average annual return is negative. It is expected after we saw the plot of portfolio value."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### _Average returns from hits (positive returns)_"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 40,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Average log return from positive bars in is 0.0010041532928493889 and counter is 40435\n",
      "Average log return from positive bars grouped by days is 0.006016279869835005 and counter is 1028\n"
     ]
    }
   ],
   "source": [
    "print('Average log return from positive bars in is' , \n",
    "      logret_series_with_short[logret_series_with_short>0].mean(), \n",
    "      'and counter is', \n",
    "      logret_series_with_short[logret_series_with_short>0].count())\n",
    "\n",
    "#Also looking at results grouped by days\n",
    "logret_by_days = logret_series_with_short.groupby(pd.Grouper(freq='D')).sum()\n",
    "logret_by_days = logret_by_days[logret_by_days!=0]\n",
    "print('Average log return from positive bars grouped by days is' , \n",
    "      logret_by_days[logret_by_days>0].mean(), 'and counter is', \n",
    "      logret_by_days[logret_by_days>0].count())"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Comparing to the previous portfolio, we have on average higher daily returns from hits (0.00601 vs 0.00595 earlier), but the counter is much lower (1028 vs 1117 earlier)."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### _Average returns from misses (negative returns)_"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 41,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Average return from negative bars is -0.0010040544557760951 and counter is 40637\n",
      "Average return from negative bars grouped by days is -0.006138036758844737 and counter is 1040\n"
     ]
    }
   ],
   "source": [
    "print('Average return from negative bars is',\n",
    "      logret_series_with_short[logret_series_with_short<0].mean(),       \n",
    "     'and counter is', \n",
    "      logret_series_with_short[logret_series_with_short<0].count())\n",
    "\n",
    "print('Average return from negative bars grouped by days is' , \n",
    "      logret_by_days[logret_by_days<0].mean(), 'and counter is',\n",
    "      logret_by_days[logret_by_days<0].count())"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Comparing to the previous portfolio, we have on average lower daily log returns (in absolute terms) from hits (-0.00613 vs -0.00622 earlier), but the counter is much higher (1040 vs 951 earlier)."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### _Annualized SR_"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 42,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Annualized Sharpe Ratio is -0.16940438831937363\n"
     ]
    }
   ],
   "source": [
    "#Using mlfinlab package function to get SR\n",
    "annualized_sr = ml.backtest_statistics.sharpe_ratio(logret_by_days, entries_per_year=252, risk_free_rate=0)\n",
    "print('Annualized Sharpe Ratio is' , annualized_sr)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "It is expected for the Sharpe ratio to be negative, as the strategy generated a loss."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Testing for Information ratio makes no sense in this situation, as it will show even lower values compared to the Annualized SR.\n",
    "\n",
    "PSR and DSR calculations make no sense when the Annualized Sharpe ratio is below zero, as it will be smaller than any positive benchmark SR."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### (b) What is the correlation to the underlying?"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "The obtained results show that on average, E-mini S&P 500 futures were growing in price. Therefore going each odd year short resulted in negative returns, because of the big growth in price in the year 2019."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Question-14.4"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### The results from a 2-year backtest are that monthly returns have a mean of 3.6%, and a standard deviation of 0.079%.\n",
    "\n",
    "### (a) What is the SR?"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Simple Sharpe ratio is calculated as:\n",
    "\n",
    "$SR=\\frac{E[r]}{\\sqrt{V[r]}}$, where $r$ - monthly returns.\n",
    "\n",
    "So, $SR = \\frac{3.6}{0.079} = 45.57$\n",
    "\n",
    "It's so high due to the standard deviation being so low. This means that 99.7% of returns fall in the (3.363%;3.837%) range. If we use the risk-free rate in the calculation, say 1.8%, then:\n",
    "\n",
    "$SR=\\frac{E[r]-R_f}{\\sqrt{V[r]}}$, where $r$ - monthly returns, $R_f$ - risk-free rate\n",
    "\n",
    "So, $SR = \\frac{3.6-1.8}{0.079} = 22.78$\n",
    "\n",
    "This SR is lower, however still high, as the standard deviation is the same."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### (b) What is the annualized SR?"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Annualized Sharpe ratio is calculated as:\n",
    "\n",
    "$SR=\\frac{E[r]}{\\sqrt{V[r]}}*\\sqrt{N}$, where $r$ - monthly returns, $N$ - number of observations per year.\n",
    "\n",
    "So, $SR = \\frac{3.6}{0.079}*\\sqrt{12} = 157.86$\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Question-14.4"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Following on exercise 1:\n",
    "### (a) The returns have a skewness of 0 and a kurtosis of 3. What is the PSR?"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "We assume it to be a typo, and that the question relates to 14.4 instead of 14.1, as the latter gives no details on exact Sharpe ratio or the number of observed returns.\n",
    "\n",
    "From a theoretical perspective, PSR corrects SR for inflationary effects caused by non-Normal returns. The skewness of 0 and kurtosis of 3 show that returns are normal."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Using the PSR formula:\n",
    "\n",
    "$PSR[SR*] = Z[\\frac{(SR - SR*)\\sqrt{T-1}}{\\sqrt{1-\\gamma_3SR+\\frac{\\gamma_4-1}{4}SR^2}}]$\n",
    "\n",
    "With SR 45 as a benchmark, \n",
    "\n",
    "$PSR[45] = Z[\\frac{(45.57-45)\\sqrt{24-1}}{\\sqrt{1-0*45.57+\\frac{3-1}{4}45.57^2}}] = 0.5338 $\n",
    "\n",
    "So, at 5% significance level, we reject that Sharpe ratio is higher than the benchmark 45 SR. Upon decreasing the benchmark:\n",
    "\n",
    "$PSR[34] = Z[\\frac{(45.57-34)\\sqrt{24-1}}{\\sqrt{1-0*45.57+\\frac{3-1}{4}45.57^2}}] = 0.9574 $\n",
    "\n",
    "So, at 5% significance level, Sharpe ratio is higher than the benchmark 34 SR. \n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 43,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Probabilistic Sharpe Ratio with 45 SR benchmark is 0.5337874636475838\n"
     ]
    }
   ],
   "source": [
    "probabilistic_sr = ml.backtest_statistics.probabilistic_sharpe_ratio(observed_sr=45.57, \n",
    "                                                                     benchmark_sr=45, \n",
    "                                                                     number_of_returns=24, \n",
    "                                                                     skewness_of_returns=0, \n",
    "                                                                     kurtosis_of_returns=3)\n",
    "print('Probabilistic Sharpe Ratio with 45 SR benchmark is' , probabilistic_sr)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 44,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Probabilistic Sharpe Ratio with 34 SR benchmark is 0.9573901697590402\n"
     ]
    }
   ],
   "source": [
    "probabilistic_sr = ml.backtest_statistics.probabilistic_sharpe_ratio(observed_sr=45.57, \n",
    "                                                                     benchmark_sr=34, \n",
    "                                                                     number_of_returns=24, \n",
    "                                                                     skewness_of_returns=0, \n",
    "                                                                     kurtosis_of_returns=3)\n",
    "print('Probabilistic Sharpe Ratio with 34 SR benchmark is' , probabilistic_sr)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### _Looking into relations between PSR and the number of observations_"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "If the same skewness and kurtosis observed in a bigger set of observations, the PSR increases. The example below shows that for a benchmark SR of 40:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 45,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Probabilistic Sharpe Ratio with 40 SR benchmark and 24 observations is 0.7963352104207573\n"
     ]
    }
   ],
   "source": [
    "probabilistic_sr = ml.backtest_statistics.probabilistic_sharpe_ratio(observed_sr=45.57, \n",
    "                                                                     benchmark_sr=40, \n",
    "                                                                     number_of_returns=24, \n",
    "                                                                     skewness_of_returns=0, \n",
    "                                                                     kurtosis_of_returns=3)\n",
    "print('Probabilistic Sharpe Ratio with 40 SR benchmark and 24 observations is' , probabilistic_sr)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 46,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Probabilistic Sharpe Ratio with 40 SR benchmark and 240 observations is 0.9962192159601215\n"
     ]
    }
   ],
   "source": [
    "probabilistic_sr = ml.backtest_statistics.probabilistic_sharpe_ratio(observed_sr=45.57, \n",
    "                                                                     benchmark_sr=40, \n",
    "                                                                     number_of_returns=240, \n",
    "                                                                     skewness_of_returns=0, \n",
    "                                                                     kurtosis_of_returns=3)\n",
    "print('Probabilistic Sharpe Ratio with 40 SR benchmark and 240 observations is' , probabilistic_sr)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### (b) The returns have a skewness of -2.448 and a kurtosis of 10.164. What is the PSR?"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### _Looking into relations between PSR and skewness/kurtosis of returns_"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Using the PSR formula with SR 45 as a benchmark, \n",
    "\n",
    "$PSR[45] = Z[\\frac{(45.57-45)\\sqrt{24-1}}{\\sqrt{1-(-2.448)*45.57+\\frac{10.164-1}{4}45.57^2}}] = 0.5156 $\n",
    "\n",
    "So, we can see that PSR decreased comparing to the PSR of returns with skewness of 0 and kurtosis of 3.\n",
    "As seen from these examples, both the decrease of skewness and increase of kurtosis result in smaller PSR :\n",
    "\n",
    "$PSR[45](skew=0, kurt=3) = Z[\\frac{(45.57-45)\\sqrt{24-1}}{\\sqrt{1-(0)*45.57+\\frac{3-1}{4}45.57^2}}] = 0.5338 $\n",
    "\n",
    "$PSR[45](skew=-2.448, kurt=3) = Z[\\frac{(45.57-45)\\sqrt{24-1}}{\\sqrt{1-(-2.448)*45.57+\\frac{3-1}{4}45.57^2}}] = 0.5321 $\n",
    "\n",
    "$PSR[45](skew=0, kurt=10.164) = Z[\\frac{(45.57-45)\\sqrt{24-1}}{\\sqrt{1-(0)*45.57+\\frac{10.164-1}{4}45.57^2}}] = 0.5158 $\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 47,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Probabilistic Sharpe Ratio with 45 SR benchmark (skew=-2.448, kurt=3) is 0.5321119245830213\n"
     ]
    }
   ],
   "source": [
    "probabilistic_sr = ml.backtest_statistics.probabilistic_sharpe_ratio(observed_sr=45.57, \n",
    "                                                                     benchmark_sr=45, \n",
    "                                                                     number_of_returns=24, \n",
    "                                                                     skewness_of_returns=-2.448, \n",
    "                                                                     kurtosis_of_returns=3)\n",
    "print('Probabilistic Sharpe Ratio with 45 SR benchmark (skew=-2.448, kurt=3) is' , probabilistic_sr)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 48,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Probabilistic Sharpe Ratio with 45 SR benchmark (skew=0, kurt=10.164) is 0.5158051263800146\n"
     ]
    }
   ],
   "source": [
    "probabilistic_sr = ml.backtest_statistics.probabilistic_sharpe_ratio(observed_sr=45.57, \n",
    "                                                                     benchmark_sr=45, \n",
    "                                                                     number_of_returns=24, \n",
    "                                                                     skewness_of_returns=0, \n",
    "                                                                     kurtosis_of_returns=10.164)\n",
    "print('Probabilistic Sharpe Ratio with 45 SR benchmark (skew=0, kurt=10.164) is' , probabilistic_sr)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 49,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Probabilistic Sharpe Ratio with 45 SR benchmark (skew=-2.448, kurt=10.164) is 0.5156231539970734\n"
     ]
    }
   ],
   "source": [
    "probabilistic_sr = ml.backtest_statistics.probabilistic_sharpe_ratio(observed_sr=45.57, \n",
    "                                                                     benchmark_sr=45, \n",
    "                                                                     number_of_returns=24, \n",
    "                                                                     skewness_of_returns=-2.448, \n",
    "                                                                     kurtosis_of_returns=10.164)\n",
    "print('Probabilistic Sharpe Ratio with 45 SR benchmark (skew=-2.448, kurt=10.164) is' , probabilistic_sr)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Question-14.6"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### What would be the PSR from 2.b, if the backtest had been for a length of 3 years?"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "We assume it to be a typo, and that the question relates to 14.5.b instead of 14.2.b, as the latter doesn't calculate PSR."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Using the PSR formula with SR 45 as a benchmark, \n",
    "\n",
    "$PSR[45] = Z[\\frac{(45.57-45)\\sqrt{36-1}}{\\sqrt{1-(-2.448)*45.57+\\frac{10.164-1}{4}45.57^2}}] = 0.5192 $\n",
    "\n",
    "So, we can see that PSR has increased when comparing to PSR from the sample of 24 observations (it was 0.5156).\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 50,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Probabilistic Sharpe Ratio with 45 SR benchmark with 36 observations is 0.5192699632499977\n"
     ]
    }
   ],
   "source": [
    "probabilistic_sr = ml.backtest_statistics.probabilistic_sharpe_ratio(observed_sr=45.57, \n",
    "                                                                     benchmark_sr=45, \n",
    "                                                                     number_of_returns=36, \n",
    "                                                                     skewness_of_returns=-2.448, \n",
    "                                                                     kurtosis_of_returns=10.164)\n",
    "print('Probabilistic Sharpe Ratio with 45 SR benchmark with 36 observations is' , probabilistic_sr)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Question-14.7"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### A 5-year backtest has an annualized SR of 2.5, computed on daily returns. The skewness is -3 and the kurtosis is 10.\n",
    "\n",
    "### (a) What is the PSR?"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Using the PSR formula with SR 2.2 as a benchmark, \n",
    "\n",
    "$PSR[2.2] = Z[\\frac{(2.5-2.2)\\sqrt{1260-1}}{\\sqrt{1-(-3)*2.5+\\frac{10-1}{4}2.5^2}}] = 0.9875 $\n",
    "\n",
    "So, at 5% significance level, Sharpe ratio is higher than the benchmark 2.2 SR. \n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 51,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Probabilistic Sharpe Ratio is 0.9874867374822187\n"
     ]
    }
   ],
   "source": [
    "probabilistic_sr = ml.backtest_statistics.probabilistic_sharpe_ratio(observed_sr=2.5, \n",
    "                                                                     benchmark_sr=2.2, \n",
    "                                                                     number_of_returns=1260, \n",
    "                                                                     skewness_of_returns=-3, \n",
    "                                                                     kurtosis_of_returns=10)\n",
    "print('Probabilistic Sharpe Ratio is' , probabilistic_sr)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### (b) In order to find that best result, 100 trials were conducted. The variance of the Sharpe ratios on those trials is 0.5. What is the DSR?"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Using the DSR formula:\n",
    "\n",
    "$SR* = \\sqrt{V[SR_n]}((1-\\gamma)*Z^{-1}[1-\\frac{1}{N}]+\\gamma*Z^{-1}[1-\\frac{1}{N}e^{-1}])$\n",
    "\n",
    "$SR* = \\sqrt{0.5}((1-\\gamma)*Z^{-1}[1-\\frac{1}{100}]+\\gamma*Z^{-1}[1-\\frac{1}{100}e^{-1}]) = 1.7894$ \n",
    "\n",
    "And:\n",
    "\n",
    "$DSR[SR*] = Z[\\frac{(SR - SR*)\\sqrt{T-1}}{\\sqrt{1-\\gamma_3SR+\\frac{\\gamma_4-1}{4}SR^2}}]$\n",
    "\n",
    "$DSR[1.7894] = Z[\\frac{(2.5-1.7894)\\sqrt{1260-1}}{\\sqrt{1-(-3)*2.5+\\frac{10-1}{4}2.5^2}}] = 0.99 $\n",
    "\n",
    "So, for the 5% significance level, SR is higher than the benchmark 1.7894. Therefore it omits multiple testing/selection bias."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 52,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Calculated benchmark Sharpe ratio is 1.7894064662732079\n",
      "Deflated Sharpe ratio is 0.9999999446183043\n"
     ]
    }
   ],
   "source": [
    "benchmark_sr_dsr = ml.backtest_statistics.deflated_sharpe_ratio(observed_sr=2.5, \n",
    "                                                                sr_estimates=[0.5**(1/2), 100], \n",
    "                                                                number_of_returns=1260, \n",
    "                                                                skewness_of_returns=-3, \n",
    "                                                                kurtosis_of_returns=10,\n",
    "                                                                estimates_param=True, benchmark_out=True)\n",
    "\n",
    "print('Calculated benchmark Sharpe ratio is', benchmark_sr_dsr)\n",
    "\n",
    "deflated_sr = ml.backtest_statistics.probabilistic_sharpe_ratio(observed_sr=2.5, \n",
    "                                                                benchmark_sr=benchmark_sr_dsr, \n",
    "                                                                number_of_returns=1260, \n",
    "                                                                skewness_of_returns=-3, \n",
    "                                                                kurtosis_of_returns=10)\n",
    "\n",
    "print('Deflated Sharpe ratio is', deflated_sr)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Conclusion"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Chapter 14 provides the formula solutions for:\n",
    " * Estimation of an average holding period;\n",
    " * Calculation of Drawdown;\n",
    " * Calculation of Time under Water;\n",
    " * Herfindahl-Hirschman Index or Concentration of returns;\n",
    " * Sharpe ratio;\n",
    " * Information ratio;\n",
    " * Probabilistic Sharpe ratio;\n",
    " * Deflated Sharpe ratio;\n",
    "\n",
    "Key takeaways from the chapter:\n",
    "\n",
    " * HHI index on dollar bars returns shows that both right and left tails of returns are close to normally distributed. Dollar bars divided into hourly bins show that time concentration of returns is low, which means returns are close to being uniformly distributed across time.\n",
    " \n",
    " * From the provided Drawdown and Time under water function, quantiles can be easily calculated in order to estimate expected drawdowns and times under water with 95% certainty.\n",
    " \n",
    " * Information ratio is a good alternative to the Sharpe ratio when taking into account the available risk-free rate.\n",
    " \n",
    " * The probabilistic Sharpe ratio (PSR) provides an adjusted estimate of SR, by removing the inflationary effect caused by short series with skewed and/or fat-tailed returns.\n",
    " \n",
    " * All else equal:\n",
    "   * Increase in the number of observations increases PSR\n",
    "   * Decrease in the skewness of returns decreases PSR\n",
    "   * Increase in the kurtosis of returns decreases PSR\n",
    " \n",
    " \n",
    " * Deflated Sharpe Ratio (DSR) is a PSR where the rejection threshold is adjusted to reflect the multiplicity of trials. DSR is estimated as PSR[SR∗], where the benchmark Sharpe ratio, SR∗, is no longer user-defined but calculated from SR estimate trails.\n",
    "\n",
    "Papers used in the chapter:\n",
    "\n",
    "* David H. Bailey and Marcos Lopez de Prado (2011): \"The Sharpe Ratio Efficient Frontier.\" Journal of Risk, Vol. 15, No. 2, Winter 2012/13. Available at https://papers.ssrn.com/abstract_id=1821643. (Provides a deeper understanding of Sharpe ratios implemented and Minimum track record length - required number of trails to conclude that the SR is above the benchmark)"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "myenv1",
   "language": "python",
   "name": "myenv1"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.6"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}
